package cn.shadow.service;

import cn.shadow.game.chess.CHnchess.ChnChessGame;
import cn.shadow.game.chess.ChessGame;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class ChessGameService {
    Map<Integer, Map<String,ChessGame>> chessMap = new HashMap<>();

    public ChessGameService(){
        Map<String, ChessGame> ChnChessGameMap = new ConcurrentHashMap<>();
        chessMap.put(1, ChnChessGameMap);
    }

    public ChessGame crate(int type) {
        Map<String, ChessGame> chessGameMap = chessMap.get(type);
        ChessGame chessGame;
        switch (type) {
            case 1:
                chessGame = new ChnChessGame();
                break;
            default:
              return null;
        }
        String gameId = UUID.randomUUID().toString();
        chessGame.setGameId(gameId);
        chessGameMap.put(gameId, chessGame);
        return chessGame;
    }

    public ChessGame get(int chessType, String gameId) {
        return chessMap.get(chessType).get(gameId);
    }
}
